$(function(){
	//paramData = {publishTime:'2015-11-21 12:12',type:'3',pageNo:'1',pageSize:'10',tag:'hj'}
	var loadDataFun = function (paramData,callback){
    	var uri = "../newsController/newsList.do";
		$.ajax({
	        type : "get",
	        dataType : "JSON",
	        url : uri, 
	        data : paramData,
	        success : function(data){
	        	if(data.success){
	        		//成功则填充数据
	        		callback(data);
	        	}
	        }, 
	        error : function(){

	        }
		});
    };
    
    
    
    	
    
    var initFun = function(){
    	var publishTime = getSearchParam('publishTime');
    	var tag = getSearchParam('tag');
    	var type = getSearchParam('type');
    	var curNavName = '';
    	switch(type){
    	case '1':
    		curNavName = 'sczx';
    		break;
    	case '2':
    		curNavName = 'jsfx';
    		break;
    	case '3':
    		curNavName = 'lsjp';
    		break;
    	}
    	$('.nav  a').each(function(){
			var name = $(this).attr('name');
			if(name == curNavName){
				$($(this).parent()).addClass('nav-active');
			} else {
				$($(this).parent()).removeClass('nav-active');
			}
		});
    	
    	if(!type){
    		type = '1';
    	}
    	
    	
    	var beginPublishTime = publishTime + ' 07:00';
    	var nextDay = getNextday(publishTime);
    	var endPublishTime = nextDay + ' 04:59';
    		
    	loadDataFun(
				{beginPublishTime:beginPublishTime,endPublishTime:endPublishTime,type:type,pageNo:'1',pageSize:'10',tag:tag}
				,function(d){
					var newsList = d.data.result;
					for(var i in newsList){
						var n = newsList[i];
						var $itemTemplate = $('#template .newsBoxTemplate').clone();
						var newsImg = $itemTemplate.find('.business-news-img').attr('src',n.coverImgPath);
						var publishTime= $itemTemplate.find('.business-news-publishTime').html(n.publishTime);
						$itemTemplate.find('.business-news-title').html(n.title);
						
						var showContent = '';//待展示的文字内容，该内容需要根据字符串长度截取
						var wrapperResult = createClippedCharacters(n.content,charNum);
	            		 if(wrapperResult.foldFlag){
	            			 showContent = wrapperResult.wrapperClippedCharacters;
	            		 } else {
	            			 showContent =  wrapperResult.wrapperWholeCharacters;
	            		 }
						
						$itemTemplate.find('.business-news-content').html(showContent);
						$itemTemplate.data('data',n);
						$itemTemplate.click(function(){
							var curData = $(this).data('data');
							
							var tCtn = $('nav > .nav-active > .nav-text').text();
							var url = 'informationDetail.html?id='+curData.id+ '&tCtn=' + tCtn;
							window.location.href = url;
						});
						
						$('.business-news-list').append($itemTemplate);
						
					}
				});
		
    };
    initFun();
});